// const BASE_URL = 'https://coke.ysxapp.cn';
const BASE_URL = 'https://sl.ysxapp.cn';
function request(url, data, token, callback) {
	uni.request({
	    url: BASE_URL + url,
	    data: data,
	    header: {
	        'token': uni.getStorageSync('token')
	    },
		method: 'POST',
	    success: (res) => {
	        callback(res.data);
			if(res.data.code == 401) {
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: '/pages/login/index/index'
					})
				}, 1500);
			}
	    }
	});
}
function request2(url, data, token, callback) {
	uni.request({
	    url: BASE_URL + url,
	    data: data,
	    header: {
	        'token': uni.getStorageSync('token')
	    },
		method: 'GET',
	    success: (res) => {
	        callback(res.data);
			if(res.data.code == 401) {
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: '/pages/login/index/index'
					})
				}, 1500);
			}
	    }
	});
}
function uploadFile(path, token, callback) {
	console.log(979797,uni.getStorageSync('token'));
	uni.uploadFile({
		url: BASE_URL + '/api/common/upload',
		filePath: path,
		name: 'file',
		header: {
		    'token': uni.getStorageSync('token')
		},
		formData: {
			'token': uni.getStorageSync('token')
		},
		success: (uploadFileRes) => {
			let upData = JSON.parse(uploadFileRes.data);
			if(upData.code == 1) {
				callback(upData);
			}
		}
	});
}

export {request, request2, uploadFile}